function y = ComputeSplineValue2( S, x )
x = double(x);
M = size(x, 2);
y = zeros(1, M);

N = size(S, 2);
if x(1) <= S(1).xp
    j = 1;
else
    if x(1) >= S(N).xp
        j = N;
    else
        i = 1;
        j = N;
        while (i + 1 < j)
            p = i + idivide(int32(j - i), 2);
            if (x(1) <= S(p).xp)
                j = k;
            else
                i = k;
            end;
        end;
        j = j - 1;
    end;
end;
   
i = 1;
poly = [S(j).d, S(j).c, S(j).b, S(j).a];
while (i <= M)
   if (x(i) >= S(j).xi && j < N)
       j = j + 1;
       poly = [S(j).d, S(j).c, S(j).b, S(j).a];
   end;
   dx = x(i) - S(j).xp;
   y(i) = polyval(poly, dx);
   i = i + 1;
end


end

